package cn.lanqiao.thread;

public class VolatileDemo {
    public static void main(String[] args) {
        Object lock = new Object();
        MyThread myThread = new MyThread();
        myThread.start();
        while (true) {
            synchronized (lock) { //清空 + pull
                if (myThread.isFlag()) {
                    System.out.println("修改完毕");
                    break;
                }
            }
        }
    }


}

class MyThread extends Thread {
    private boolean flag = false;

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        flag = true;
    }

    public boolean isFlag() {
        return flag;
    }

}
